﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace UNFEventPosting.Models
{
    public class Event : IValidatableObject
    {
        public Guid ID { get; set; }
       
        [Required(ErrorMessage = "Your N number is required!")]
        [Display(Name = "N Number")]
        [RegularExpression(@"^[Nn]\d{8}$", ErrorMessage = "Give your N number in the following format: N00000000")]
        public String N_Number { get; set; }

        [Required(ErrorMessage = "The event name is required!")]
        [Display(Name = "Event Name")]
        public String Name { get; set; }

        [Required(ErrorMessage = "An event category is required!")]
        [Display(Name = "Category")]
        [Range(0, int.MaxValue)]
        public int CategoryID { get; set; }
        public virtual Category Category { get; set; }

        [Display(Name = "Event Description")]
        public String Description { get; set; }

        [Required(ErrorMessage  = "The event start time is required!")]
        [DisplayFormat(DataFormatString = "{0:f}")]
        [Display(Name = "Start Date-Time")]
        public DateTime StartTime { get; set; }

        [Required(ErrorMessage = "The event end time is required!")]
        [DisplayFormat(DataFormatString = "{0:f}")]
        [Display(Name = "End Date-Time")]
        public DateTime EndTime { get; set; }

        [Required]
        public String Location { get; set; }

        public String Notes { get; set; }
        
        [HiddenInput]
        public bool Confirmed { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (EndTime < DateTime.Now)
            {
                yield return new ValidationResult("You cannot submit an event that ended in the past!");
            }

            if (StartTime > EndTime)
            {
                yield return new ValidationResult("The start time cannot be after the end time!");
            }
        }
    }
}